<template>
  <div class="newappoint">
    <div class="nav-title">基本信息</div>
    <el-form
      ref="newStudentForm"
      :model="newStudentForm"
      :rules="newStudentRules"
      label-width="150px"
    >
      <el-form-item label="学员姓名" prop="name">
        <el-input v-model="newStudentForm.name" style="width:300px;" />
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="newStudentForm.sex">
          <el-radio label="man">男</el-radio>
          <el-radio label="woman">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="手机号" prop="contact">
        <el-input v-model="newStudentForm.contact" style="width:300px;" />
      </el-form-item>
      <el-form-item label="出身日期" prop="birthday">
        <el-date-picker
          v-model="newStudentForm.birthday"
          type="date"
          placeholder="选择日期"
          style="width:300px;"
        />
      </el-form-item>
      <el-form-item label="微信号">
        <el-input v-model="newStudentForm.wechat" style="width:300px;" />
      </el-form-item>
      <el-form-item label="年级">
        <el-select v-model="newStudentForm.grade" placeholder="请选择" style="width:300px;">
          <el-option
            v-for="item in gradeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="地域">
        <el-cascader
          v-model="newStudentForm.territory"
          :options="territoryOptions"
          style="width:300px;"
        />
      </el-form-item>
      <el-form-item label="详细地址">
        <el-input v-model="newStudentForm.address" style="width:300px;" />
      </el-form-item>
      <div class="nav-title">售卖信息</div>
      <el-form-item label="来源渠道" prop="source">
        <el-select v-model="newStudentForm.source" placeholder="请选择" style="width:300px;">
          <el-option
            v-for="item in sourceOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="意向课程" prop="intentCourse">
        <el-button v-show="!newStudentForm.intentCourse" @click="selectCourseDialog=true">选择课程</el-button>
        <div v-show="newStudentForm.intentCourse" class="course-tag">
          <div class="course-title">{{ newStudentForm.intentCourse }}</div>
          <el-button v-show="newStudentForm.intentCourse" @click="selectCourseDialog=true">更换课程</el-button>
        </div>
      </el-form-item>
      <el-form-item label="意向度">
        <el-select v-model="newStudentForm.intention" placeholder="请选择">
          <el-option
            v-for="item in intentionOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="跟进人" prop="followPerson">
        <el-button v-show="!newStudentForm.followPerson" @click="selectfollowmenDialog=true">选择跟进人</el-button>
        <div v-show="newStudentForm.followPerson" class="course-tag">
          <div class="course-title">{{ newStudentForm.followPerson }}</div>
          <el-button v-show="newStudentForm.followPerson" @click="selectfollowmenDialog=true">更换跟进人</el-button>
        </div>
      </el-form-item>
    </el-form>
    <div class="foot-btn">
      <el-button @click="cancelForm">取消</el-button>
      <el-button type="primary" @click="saveForm">保存</el-button>
    </div>
    <!-- 选择课程弹框 -->
    <createCourseDialog
      :dialog="selectCourseDialog"
      @cancelClick="cancelClick"
      @confirmClick="confirmCourseClick"
    />
    <!-- 选择跟近人弹框 -->
    <followmendialog
      :dialog="selectfollowmenDialog"
      @cancelClick="cancelClick"
      @confirmClick="confirmFollowmenlick"
    />
  </div>
</template>

<script>
import createCourseDialog from '../class/coursedialog'
import followmendialog from '../aligncourse/followmendialog'
export default {
  components: {
    createCourseDialog,
    followmendialog
  },
  data() {
    return {
      selectCourseDialog: false,
      selectfollowmenDialog: false,
      newStudentForm: {
        name: '',
        birthday: '',
        sex: 'man',
        age: '',
        wechat: '',
        territory: [],
        address: '',
        grade: '',
        contact: '',
        studentNum: 'S2019080515',
        source: '',
        intentCourse: '',
        intentCourseId: '',
        followPerson: '',
        followPersonId: '',
      },
      territoryOptions: [
        {
          value: '北京',
          label: '北京',
          children: [{
            value: '市辖区',
            label: '市辖区',
            children: [{
              value: '海淀区',
              label: '海淀区'
            }, {
              value: '朝阳区',
              label: '朝阳区'
            }, {
              value: '东城区',
              label: '东城区'
            }, {
              value: '西城区',
              label: '西城区'
            }]
          }
          ]
        }
      ],
      gradeOptions: [
        {
          value: '一年级',
          label: '一年级'
        },
        {
          value: '二年级',
          label: '二年级'
        },
        {
          value: '三年级',
          label: '三年级'
        },
        {
          value: '四年级',
          label: '四年级'
        },
        {
          value: '五年级',
          label: '五年级'
        },
        {
          value: '六年级',
          label: '六年级'
        },
      ],
      sourceOptions: [
        {
          value: '在线购买',
          label: '在线购买'
        },
        {
          value: '在线招生',
          label: '在线招生'
        },
        {
          value: '来电咨询',
          label: '来电咨询'
        },
        {
          value: '地推',
          label: '地推'
        },
        {
          value: '外呼电话',
          label: '外呼电话'
        },
        {
          value: '转介绍',
          label: '转介绍'
        },
        {
          value: '客户直访',
          label: '客户直访'
        },
        {
          value: '其他',
          label: '其他'
        }
      ],
      intentionOptions: [
        {
          value: '高',
          label: '高'
        },
        {
          value: '中',
          label: '中'
        },
        {
          value: '低',
          label: '低'
        }
      ],
      newStudentRules: {
        name: [{ required: true, message: '请输入学员姓名', trigger: 'blur' }],
        contact: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        source: [{ required: true, message: '请选择来源渠道', trigger: 'change' }],
      },
    }
  },
  methods: {
    cancelForm() {
      this.$refs.newStudentForm.resetFields()
      this.$router.go(-1)
    },
    saveForm() {
      this.$refs.newStudentForm.validate((valid) => {
        if (valid) {
          this.$refs.newStudentForm.resetFields()
          this.$router.go(-1)
        } else {
          return false
        }
      })
    },
    cancelClick() {
      this.selectCourseDialog = false
      this.selectfollowmenDialog = false
    },
    // 接收选择课程弹框事件
    confirmCourseClick(data) {
      this.selectCourseDialog = false
      this.newStudentForm.intentCourseId = data.id
      this.newStudentForm.intentCourse = data.name
    },
    // 接收选择员工弹框事件
    confirmFollowmenlick(data) {
      this.selectfollowmenDialog = false
      this.newStudentForm.followPersonId = data.id
      this.newStudentForm.followPerson = data.name
    },
  }
}
</script>

<style lang="scss" scoped>
.newappoint {
  padding: 0 20px;
  padding-bottom: 50px;
  .nav-title {
    padding-left: 10px;
    margin: 20px 0;
    font-size: 16px;
    font-weight: 600;
    color: #353535;
    border-left: 2px solid #2377e6;
  }
  .course-tag {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 480px;
    height: 60px;
    padding: 10px 20px 10px 10px;
    color: #353535;
    font-size: 0;
    background: #f5f7fa;
    .course-title {
      width: 210px;
      overflow: hidden;
      font-weight: 700;
      font-size: 14px;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
  .foot-btn {
    position: fixed;
    bottom: 0;
    box-sizing: border-box;
    width: calc(100vw - 180px);
    height: 60px;
    line-height: 60px;
    border-top: 1px solid #eee;
    text-align: center;
    background-color: #fff;
    z-index: 9;
  }
}
</style>